package com.zhangtai.modules.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangtai.modules.entity.transfer.TransferInfoEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-07-06 11:33:03
 */
@Mapper
public interface TransferInfoDao extends BaseMapper<TransferInfoEntity> {

    @Select("<script> " +
            "Select transfer.* from tb_transfer_info transfer  " +
            "left join tb_employee_info info on info.oid = transfer.oid  " +
                "<where> transfer.is_delete = 0 " +
                    "<if test='userCode!=null'> and info.code = #{userCode} </if>" +
                    "<if test='name!=null'> and info.name like '%${name}%' </if>" +
                    "<if test='unitname!=null'> and info.code = #{unitname} </if>" +
                    "<if test='orgname!=null'> and info.code = #{orgname} </if>" +
                    "<if test='type!=null'> and transfer.type = #{type} </if>" +
                    "<if test='transferType!=null'> and transfer.transfer_type = #{transferType} </if>" +
                    "<if test='dealStatus!=null'> and transfer.deal_status = #{dealStatus} </if>" +
                    "<if test='orgIds!=null and orgIds.size>0'> and ( transfer.before_department_id in " +
                        "<foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach> " +
                        " or transfer.after_department_id in " +
                        "<foreach item=\"orgId\" index=\"index\" collection=\"orgIds\" open=\"(\" separator=\",\" close=\")\">#{orgId}</foreach> )" +
                     "</if>"+
                    "<if test='jobIds!=null and jobIds.size>0'> and info.job_id in " +
                         "<foreach item=\"jobId\" index=\"index\" collection=\"jobIds\" open=\"(\" separator=\",\" close=\")\">#{jobId}</foreach>" +
                    "</if>"+
                     "<if test='jobSystemIds!=null and jobSystemIds.size>0'> and info.job_system_id in " +
                        "<foreach item=\"jobSystemId\" index=\"index\" collection=\"jobSystemIds\" open=\"(\" separator=\",\" close=\")\">#{jobSystemId}</foreach>" +
                     "</if>"+
                    "<if test='orgIds==null or orgIds.size==0'> and info.unit_id = null </if>" +
            "<if test='jobIds!=null and jobIds.size==0'> and info.job_id =null </if>" +
            "<if test='jobSystemIds!=null and jobSystemIds.size==0'> and info.job_system_id =null </if>" +

                "</where>" +
            " order by transfer.create_time desc " +
            "</script>")
    List<TransferInfoEntity> getTransferList(@Param("transferType")Integer transferType,@Param("unitname")String unitname,@Param("orgname")String orgname,@Param("userCode")String userCode,
                                             @Param("name")String name,@Param("type")Integer type,@Param("dealStatus")Integer dealStatus, @Param("jobIds")List<Long> jobIds,
                                             @Param("jobSystemIds")List<Long> jobSystemIds,@Param("orgIds")List<Long> orgIds, Page<TransferInfoEntity> page);

}
